﻿<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>书籍列表</title>
    <link rel="stylesheet" type="text/css" th:href="@{/manager/easyui/themes/default/easyui.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/manager/easyui/themes/icon.css}">
    <script type="text/javascript" th:src="@{/manager/easyui/jquery.min.js}"></script>
    <script type="text/javascript" th:src="@{/manager/easyui/jquery.easyui.min.js}"></script>
	<script type="text/javascript">
        var rows=null;
        var pressid=null;
        var supplierId=null;
	    //工具栏
	    var toolbar = [{
	        text: '修改',
	        iconCls: 'icon-edit',
	        handler: function () {
	            $('#dd').dialog('open');
                var row =$('#booklist').datagrid('getSelected');
               $('#bookName').textbox('setValue',row.bookName);
               $('#price').textbox('setValue',row.price);
               $('#myId').attr('value',row.id)
               $('#groupPrice').textbox('setValue',row.groupPrice);
               $('#bookIntroduce').textbox('setValue',row.bookIntroduce);
               $('#authorIntroduce').textbox('setValue',row.authorIntroduce);








	        }
	    }, '-', {
	        text: '启用',
	        iconCls: 'icon-ok',
	        handler: function () {
	            var row =$('#booklist').datagrid('getSelected');
	            $.ajax({
                    url:'/manager/book/modifyStatusEnable',
                    dataType:'json',
                    data:{
                            'id':row.id},
                    type: 'get',
                    success:function (result) {
                        console.log(result)
                        $('#booklist').datagrid('reload')
	                  alert('ok')


                    }

                })

	        }
	    }, '-', {
	        text: '禁用',
	        iconCls: 'icon-cancel',
	        handler: function () {
                var row =$('#booklist').datagrid('getSelected');
                $.ajax({
                    url:'/manager/book/modifyStatusDisable',
                    dataType:'json',
                    data:{
                        'id':row.id},
                    type: 'get',
                    success:function () {
                        $('#booklist').datagrid('reload')
                        alert('ok')


                    }

                })


	        }
	    }];
	   $(function(){

            $('#search_press').combobox({
                url:"/manager/book/findPress",
                valueField:"id",
                textField:'name',
                onChange:function (newValue) {
                    pressid=newValue
                }
            })





	       $('#booklist').datagrid({  
				title:'书籍列表',  
				iconCls:'icon-save',   
				url:'/manager/book/findAll',
				columns:[
				    [
					{field:'bookName',title:'名称',width:100,align:'center'},
					{field:'author',title:'作者',width:200,align:'center'},
					{field:'price',title:'单价',width:80,align:'center'},
					{field:'ISBN',title:'ISBN',width:200,align:'center'},
					{field:'press',title:'出版社',width:200,align:'center',formatter:function(value,row,index){
					return row.press.name
                    }
                    },
	                {field:'supplierList',title:'供货商',width:500,align:'center',formatter:function(value,row,index){
	                    var names="";
	                    for (var i=0;i<row.supplierList.length;i++){
                            names+=row.supplierList[i].name;
                            if(i!=row.supplierList.length-1){
                                names+=",";
                            }
                        }
                        return names;


                        }},
                    {field:'flag',title:'状态',width:100,align:'center',formatter:function(value,row,index){
                            if(value==1){
                                return "启用"
                            }
                            if(value==2){
                                return "禁用"
                            }

                                return "无效数据"

                        }}
				]
                ],
				toolbar: toolbar,
				pagination: true,//表示在datagrid设置分页              
               	pageSize: 5,
				singleSelect:true,
                pageList: [5,10,20]
			});

		 //初始化查询栏
		 $("#submit_search").linkbutton({ iconCls: 'icon-search', plain: true })
            .click(function () {
                $('#booklist').datagrid({ queryParams: {
                        'bookName':$('#myBookName').val(),
                        'ISBN':$('#ISBN').val(),
                        'pressid':$('#search_press').val()
                    },
                });   //点击搜索
            });
          
          //初始化修改窗口  
         $('#dd').dialog({
			    title: 'My Dialog',
			    width: 700,
			    height: 500,
			    closed: true,
			    cache: false,
			    href: '',
			    modal: true,
			    iconCls: 'icon-save',
                buttons: [{
                    text:'提交',
                    iconCls:'icon-ok',
                    handler:function(){
                        $('#ff').submit();


                        alert('ok');
                    }
                },{
                    text:'关闭',
                    handler:function(){
                        alert('cancel');;
                    }
                }]
			});


	   });


	</script>
</head>
<body>
   <form name="searchform" method="post"   id ="searchform">
    <td width="70" height="30"><strong>书籍查询：</strong></td>
    <td height="30">
        <input type="text" name="bookName" id="myBookName" size=20 placeholder="书籍名称"/>
        <input type="text" name="ISBN" id="ISBN" size=20 placeholder="ISBN"/>
        <select name="pressid" id="search_press"  >
            <option value="-1" id="selectedPress" name="请选择出版社">请选择出版社</option>
            <option></option>
        </select>
        <select name="supplierId" id="search_supplier" >
            <option value="-1" name="请选择供应商">请选择供应商</option>
            <option   th:text="${supplier}"></option>
        </select>
        编辑推荐:<input type="checkbox" name="" value=""/>
        本周精选:<input type="checkbox" name="" value=""/>
    </td>
	<td>
	  <a id="submit_search">搜索</a>
	</td>
  </form>
  <table id="booklist"></table>
    <div id="dd">
           <div align="center" style="margin-top: 30px">
            <form id="ff" method="post" th:action="@{/manager/book/modifyBook}" enctype="multipart/form-data">
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" id="bookName" name="bookName" style="width:50%" data-options="label:'书籍名称:',required:true">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" id="price" name="price" style="width:50%" data-options="label:'单价:',required:true,validType:'email'">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" id="groupPrice" name="groupPrice" style="width:50%" data-options="label:'团购价:',required:true">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" id="bookIntroduce" name="bookIntroduce" style="width:50%;height:60px" data-options="label:'书籍简介:',multiline:true">
            </div>
             <div style="margin-bottom:20px">
                <input class="easyui-textbox" id="authorIntroduce" name="authorIntroduce" style="width:50%;height:60px" data-options="label:'作者简介:',multiline:true">
                 <input type="hidden" name="id" id="myId" value="">
            </div>
             <div style="margin-bottom:20px">
               封面图片:&nbsp;&nbsp;&nbsp;&nbsp; <input  name="somefile" type="file"/>
            </div>
            <div style="margin-bottom:20px">
               编辑推荐:<input type="checkbox" name="" value=""/>
               本周精选:<input type="checkbox" name="" value=""/>
            </div>
        </form>
           </div>
    </div>
</body>
</html>